﻿using CrewCalculator.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CrewCalculator.Drivers
{
    public class CrewCalculatorDriver : ContentPartDriver<CrewCalculatorPart>
    {
        protected override DriverResult Display(
            CrewCalculatorPart part, string displayType, dynamic shapeHelper)
        {
            return ContentShape("Parts_CrewCalculator",
                () => shapeHelper.Parts_CrewCalculator(
                    UserName: part.UserName,
                    Species: part.Species,
                    ShipCrew: part.ShipCrew,
                    CurrentCrew: part.CurrentCrew,
                    ShipStrengthPercentage: (part.CurrentCrew / part.ShipCrew) * 100
                    ));
        }

        //GET
        protected override DriverResult Editor(CrewCalculatorPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_CrewCalculator_Edit",
                () => shapeHelper.EditorTemplate(
                    TemplateName: "Parts/CrewCalculator",
                    Model: part,
                    Prefix: Prefix));
        }

        //POST
        protected override DriverResult Editor(
            CrewCalculatorPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }

    }
}